package com.jyy.prefabricated.controller;


import com.jyy.prefabricated.common.AjaxResult;
import com.jyy.prefabricated.dto.AnswerDto;
import com.jyy.prefabricated.entity.Student;
import com.jyy.prefabricated.mapper.QuestionMapper;
import com.jyy.prefabricated.service.StudentExerciseQuestionService;
import com.jyy.prefabricated.utils.UserUtils;
import com.jyy.prefabricated.vo.StudentExercisePaperVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 学员练习题目
 * @version 1.0.0
 * @author: zjj
 */
@Slf4j
@RequestMapping("/api")
@RestController
public class StudentExerciseQuestionController {

    @Autowired
    private StudentExerciseQuestionService studentExerciseQuestionService;

    @Autowired
    private UserUtils userUtils;


    /**
     * 答题
     * @param dto
     * @return
     */
    @PutMapping("/student-exercise-question")
    public AjaxResult update(@Valid @RequestBody AnswerDto dto){
        log.info("Rest request to update studentExamQuestion:{}",dto);
        StudentExercisePaperVo result = studentExerciseQuestionService.answer(dto);
        return AjaxResult.success(result);
    }

    /**
     * 获取试题
     * @param studentExerciseId 学生练习id
     * @return
     */
    @GetMapping("/student-exercise-question/{studentExerciseId}")
    public AjaxResult selectById(@PathVariable Integer studentExerciseId){
        log.info("Rest request to find studentExamQuestion by id:{}",studentExerciseId);
        //StudentExercisePaperVo result = studentExerciseQuestionService.fetchQuestionsByStudentExerciseId(studentExerciseId);

        StudentExercisePaperVo result = studentExerciseQuestionService.fetchQuestionsByStudentExerciseIdAnswer(studentExerciseId);
        return AjaxResult.success(result);
    }

    /**
     * 查看练习详情（获取试题包括标准答案）
     * @param studentExerciseId
     * @return
     */
    @GetMapping("/student-exercise/{studentExerciseId}")
    public AjaxResult selectByStudentExerciseId(@PathVariable Integer studentExerciseId){

        StudentExercisePaperVo result = studentExerciseQuestionService.fetchQuestionsByStudentExerciseIdAnswer(studentExerciseId);
        return AjaxResult.success(result);
    }


}
